<?php

namespace app\teacher\controller\learn;

use app\common\controller\Frontend;
use app\common\model\banxi\learn\LearnTwentyAntiForgetting as LearnTwentyAntiForgettingModel;
use think\facade\Log;

/*
 * 21天抗遗忘
 * */
class LearnTwentyAntiForgetting extends Frontend
{
    protected array $noNeedLogin = [''];

    protected array $noNeedPermission = ['*'];

    public function initialize(): void
    {
        parent::initialize();
    }

    /*
     * 查询-我当天的抗遗忘记录
     * */
    public function listMyDayList()
    {
        // 获取当前用户ID
        $trainerId = $this->auth->id;

        // 查询符合条件的抗遗忘记录
        $LearnTwentyAntiForgettingModel = new LearnTwentyAntiForgettingModel();
        $trainerList = $LearnTwentyAntiForgettingModel
            ->with(['studentInfo'])
            ->where('trainerAntiForgettingId', $trainerId)
            ->where('date', date('Y-m-d')) // 当天日期
            ->select();

        // 按日期分组包装结果
        $result = $LearnTwentyAntiForgettingModel->wrapperReviewDate($trainerList);

        $this->ok('操作成功', $result);
    }

    /*
     * 查询-我当天的抗遗忘记录V2
     * */
    public function listMyDayListV2()
    {
        // 获取当前用户ID
        $trainerId = $this->auth->id;

        // 查询符合条件的抗遗忘记录
        $LearnTwentyAntiForgettingModel = new LearnTwentyAntiForgettingModel();
        $trainerList = $LearnTwentyAntiForgettingModel
            ->with(['studentInfo'])
            ->where('trainerAntiForgettingId', $trainerId)
            ->where('date', date('Y-m-d')) // 当天日期
            ->select();

        // 按日期分组包装结果
        $result = $LearnTwentyAntiForgettingModel->wrapperReviewDateV2($trainerList);

        $this->ok('操作成功', $result);
    }

    /**
     * 查询-我的抗遗忘记录
     *
     * @return \think\response\Json
     */
    public function listMyList()
    {
        // 获取当前用户ID
        $trainerId = $this->auth->id;

        // 查询符合条件的抗遗忘记录（日期大于等于今天）
        $LearnTwentyAntiForgettingModel = new LearnTwentyAntiForgettingModel();
        $trainerList = $LearnTwentyAntiForgettingModel
            ->with(['studentInfo'])
            ->where('trainerAntiForgettingId', $trainerId)
            ->where('date', '>=', date('Y-m-d')) // 日期大于等于今天
            ->select();

        // 按日期分组包装结果
        $result = $LearnTwentyAntiForgettingModel->wrapperReviewDate($trainerList);

        $this->ok('操作成功', $result);
    }

}